<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: relative;
            width: 100px;
            height: 100px;
            background-color: pink;
            left: 10px;
            top: 10px;
        }
    </style>
</head>

<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        // div.addEventListener('touchstart', function(e) {
        //     console.log(e.targetTouches[0]);
        //     console.log('我摸了你');
        // })
        // div.addEventListener('touchmove', function() {
        //     console.log('我继续摸');
        // })
        // div.addEventListener('touchend', function() {
        //     console.log('轻轻的我走了');
        // })
        //手指的位置
        var startX = 0;
        var startY = 0;
        //盒子的位置
        var x = 0;
        var y = 0;
        div.addEventListener('touchstart', function(e) {
            startX = e.targetTouches[0].pageX;
            startY = e.targetTouches[0].pageY;
            x = this.offsetLeft;
            y = this.offsetTop;
        })
        div.addEventListener('touchmove', function(e) {
            var moveX = e.targetTouches[0].pageX - startX;
            var moveY = e.targetTouches[0].pageY - startY;
            this.style.left = x + moveX + 'px';
            this.style.top = y + moveY + 'px';
            e.preventDefault(); //阻止滚动的影响
        })
    </script>
</body>

</html>